using UnityEngine;
using System.Collections;
 
public class FPSDisplay : MonoBehaviour 
{
	public  float updateInterval = 0.5F;
	 
	private float accum   = 0;
	private int   frames  = 0;
	private float timeleft;
	private string fpstext = "";
 
	void Start()
	{
	    timeleft = updateInterval;  
	}
	
	void OnGUI()
	{
		timeleft -= Time.deltaTime;
    	accum += Time.timeScale/Time.deltaTime;
    	++frames;
 
	    if( timeleft <= 0.0 )
	    {
			float fps = accum/frames;
			fpstext = System.String.Format("{0:F2} FPS",fps);
	 
	        timeleft = updateInterval;
	        accum = 0.0F;
	        frames = 0;
	    }
		
		GUI.Label(new Rect(5, 5, 200, 35), fpstext, GameManager.GM.guiStyle);
	}
}
